package org.jcc.core.cs.functional;

import java.util.function.Function;

public class FunctionalSum {
	
	public static void main(String[] args) {
		int idSum = sum(MathUtil::identity);
		int sqSum = sum(MathUtil::square);
		int cbSum = sum(MathUtil::cube);
		
		int dbSum = sum(i -> 2 * i);
		int qrSum = sum(i -> i * i * i * i);
		
		System.out.print(idSum + " " + sqSum + " " + cbSum + " " + dbSum + " " + qrSum);
		
		
		double sqSum2 = sumf(i -> Math.pow(i, 2));
		double cbSum2 = sumf(i -> Math.pow(i, 3));
		System.out.println(sqSum2 + " " + cbSum2);
		

		double sinSum = sumf(Math::sin);
		System.out.println(sinSum);
	}
	
	public static int sum(Function<Integer, Integer> f) {
		int sum = 0;
		for (int i = 1; i <= 100; i++) {
			sum += f.apply(i);
		}
		return sum;
	}
	
	public static double sumf(Function<Double, Double> f) {
		double sum = 0;
		for (int i = 1; i <= 100; i++) {
			sum += f.apply((double) i);
		}
		return sum;
	}
}
